package com.M10.BE.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;


import com.M10.BE.R;
import com.M10.BE.entity.NAsset;

import java.util.List;

/**
 * Created by Administrator on 2018/8/14.
 */

public class NNewAdapter extends BaseAdapter {
    private Context mContext;
    private List<NAsset> list;
    private Holder holder = null;
    private ListView listView;

    public NNewAdapter(Context context, List<NAsset> list, ListView listView) {
        this.mContext = context;
        this.list = list;
        this.listView = listView;
    }

    public List<NAsset> getList() {
        return list;
    }

    public void clearData() {
        list.clear();
    }

    public void setList(List<NAsset> list) {
        this.list = list;
    }

    @Override
    public int getCount() {
        return list == null ? 0 : list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_total_asset_list, null);
            holder.tv_assetName = (TextView) convertView
                    .findViewById(R.id.tv_item_name);
            holder.tv_assetCode = (TextView) convertView.findViewById(R.id.tv_item_code);
            holder.tv_assetNum = (TextView) convertView
                    .findViewById(R.id.tv_item_num);
//            holder.tv_assetjCount = (TextView) convertView
//                    .findViewById(R.id.tv_item_jcount);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        NAsset asset = list.get(position);
        holder.tv_assetName.setText(asset.getName());
//        holder.tv_assetjCount.setText(asset.getjCount());
        holder.tv_assetNum.setText(asset.getCnum());
        holder.tv_assetCode.setText(asset.getZcNo());
        return convertView;
    }

    class Holder {
        TextView tv_assetName;
        TextView tv_assetCode;
        TextView tv_assetNum;
//        TextView tv_assetjCount;
    }
}